1 package org.apache.maven.surefire.common.junit48;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import org.apache.maven.surefire.NonAbstractClassFilter;
24 import org.apache.maven.surefire.common.junit4.JUnit4TestChecker;
25 import org.apache.maven.surefire.util.ScannerFilter;
26 import org.junit.experimental.runners.Enclosed;
27
28
29
30
31
32
33
34 public class JUnit48TestChecker
35 implements ScannerFilter
36 {
37 private final NonAbstractClassFilter nonAbstractClassFilter;
38
39 private final JUnit4TestChecker jUnit4TestChecker;
40
41
42 public JUnit48TestChecker( ClassLoader testClassLoader )
43 {
44 this.jUnit4TestChecker = new JUnit4TestChecker( testClassLoader );
45 this.nonAbstractClassFilter = new NonAbstractClassFilter();
46 }
47
48 public boolean accept( Class testClass )
49 {
50 return jUnit4TestChecker.accept( testClass ) || isAbstractWithEnclosedRunner( testClass );
51 }
52
53 @SuppressWarnings( { "unchecked" } )
54 private boolean isAbstractWithEnclosedRunner( Class testClass )
55 {
56 return jUnit4TestChecker.isRunWithPresentInClassLoader()
57 && isAbstract( testClass )
58 && isRunWithEnclosedRunner( testClass );
59 }
60
61 private boolean isRunWithEnclosedRunner( Class testClass )
62 {
63 @SuppressWarnings( "unchecked" ) org.junit.runner.RunWith runWithAnnotation =
64 (org.junit.runner.RunWith) testClass.getAnnotation( org.junit.runner.RunWith.class );
65 return ( runWithAnnotation != null && Enclosed.class.equals( runWithAnnotation.value() ) );
66 }
67
68 private boolean isAbstract( Class testClass )
69 {
70 return !nonAbstractClassFilter.accept( testClass );
71 }
72 }